#include "floatTool.h"
#include "ui_floatTool.h"

FloatTool::FloatTool(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FloatTool)
{
    ui->setupUi(this);
}

FloatTool::~FloatTool()
{
    delete ui;
}

void FloatTool::on_comboBox_currentIndexChanged(int index)
{
    m_setEndian = (index==0)?true:false;
    on_pushButton_released();
}

void FloatTool::on_lineEdit_editingFinished()
{
   m_setValue.src = ui->lineEdit->text().toFloat();
}


void FloatTool::on_pushButton_released()
{
    QString tmp;
    if(m_setEndian)
        tmp = QString("0x%1%2%3%4").arg(m_setValue.dec[3], 2, 16, QLatin1Char('0')) \
                .arg(m_setValue.dec[2], 2, 16, QLatin1Char('0')) \
                .arg(m_setValue.dec[1], 2, 16, QLatin1Char('0')) \
                .arg(m_setValue.dec[0], 2, 16, QLatin1Char('0'));
    else
        tmp = QString("0x%1%2%3%4").arg(m_setValue.dec[0], 2, 16, QLatin1Char('0')) \
                .arg(m_setValue.dec[1], 2, 16, QLatin1Char('0')) \
                .arg(m_setValue.dec[2], 2, 16, QLatin1Char('0')) \
                .arg(m_setValue.dec[3], 2, 16, QLatin1Char('0'));

    qDebug("%s:%02x %02x %02x %02x %f", __FUNCTION__, m_setValue.dec[0],  m_setValue.dec[1], \
            m_setValue.dec[2], m_setValue.dec[3],m_setValue.src);
    ui->label->setText(tmp);
}

void FloatTool::on_lineEdit_textChanged(const QString &arg1)
{
    m_setValue.src = ui->lineEdit->text().toFloat();
}